package com.ym.jiujiangeyou.parse;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import com.ym.jiujiangeyou.entity.SimpleWeather;
import com.ym.jiujiangeyou.entity.Weather;
 /**   
 * @author 叶铭   
 * @email yeming_1001@163.com
 * @version V1.0   
 * @Description: 天气数据处理 
 */
public class WeatherParse {

	public WeatherParse() {
	}

	/** 
	* @param weather
	* @return  
	* @retur  String 
	* @Description: 转换Weather为Json数据
	*/
	public static String WeatherToJson(Weather weather){
		Gson gson = new Gson() ;
		String json = gson.toJson(weather).toString() ;
		return json ;
	}
	/** 
	* @param simpleWeather
	* @return  
	* @retur  String 
	* @Description: 转换SimpleWeather为Json数据
	*/
	public static String SimpleWeatherToJson(SimpleWeather simpleWeather){
		Gson gson = new Gson() ;
		String json = gson.toJson(simpleWeather).toString() ;
		return json ;
	}
	
	/** 
	* @param weatherJson
	* @return  
	* @retur  Weather 
	* @Description: 解析weather Json数据
	*/
	public static Weather getWeatherFormJson(String weatherJson){
		Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
				.create();
		Weather weather = gson.fromJson(weatherJson, new TypeToken<Weather>(){}.getType()) ;
		return weather ;
	}
	
	/** 
	* @param simpleWeatherJson
	* @return  
	* @retur  SimpleWeather 
	* @Description: 解析SimpleWeather Json数据 
	*/
	public static SimpleWeather getSimpleWeatherFormJson(String simpleWeatherJson){
		Gson gson = new GsonBuilder().excludeFieldsWithoutExposeAnnotation()
				.create();
		SimpleWeather simpleWeather = gson.fromJson(simpleWeatherJson, new TypeToken<SimpleWeather>(){}.getType()) ;
		return simpleWeather ;
	}
	
}
